<?php 
class model_company extends Model
{
	
	function construct()
	{
		parent::__construct();
	}
	
	function newCompany($data)
	{
		$this->db->insert("company", $data);
	
	}

	function updateCompany($data, $id)
	{
		$this->db->update("company", $data, array("id" => $id));
	}
	
	
	function removeCompany($id)
	{
		$this->updateCompany(array("active" => 0), $id);
	}
	
	function getAll()
	{
		$this->db->select("company.*, lu.lu_lable as state")
			 ->from("company")
			 ->join("lookup lu", "lu.lu_value=company.company_state and lu.lu_type='states'")
			 ->where(array("active" => 1, "company_parent" => $_SESSION['user_company']))
			 ->group_by("company.id");
		$r = $this->db->get();
		
		return $r->result_array();
	}
	
	function getClient($id)
	{
		$this->db->select("company.*, lu.lu_lable as state")
			->from("company")
			->join("lookup lu", "lu.lu_value=company.company_state  and lu.lu_type='states'")
			->where(array("company.id" => $id, "company_parent" => $_SESSION['user_company']));
			
		$r = $this->db->get();
		
		return  $r->result_array();
	}
	

	
}